{% extends 'todo/base.html' %}

{% block title %}科目管理 - 考研学习计划{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card shadow-sm">
                <div class="card-header bg-success text-white">
                    <h4 class="mb-0"><i class="bi bi-plus-circle"></i> 添加新科目</h4>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        <input type="hidden" name="action" value="create">
                        
                        <div class="mb-3">
                            <label for="name" class="form-label">科目名称 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="name" name="name" 
                                   placeholder="例如：英语、数学、政治等" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="color" class="form-label">标签颜色</label>
                            <div class="input-group">
                                <input type="color" class="form-control form-control-color" 
                                       id="color" name="color" value="#007bff">
                                <input type="text" class="form-control" id="color-text" 
                                       value="#007bff" readonly>
                            </div>
                            <small class="text-muted">选择一个颜色来标识这个科目</small>
                        </div>
                        
                        <button type="submit" class="btn btn-success w-100">
                            <i class="bi bi-plus-circle"></i> 添加科目
                        </button>
                    </form>
                </div>
            </div>
        </div>
        
        <div class="col-md-6 mb-4">
            <div class="card shadow-sm">
                <div class="card-header bg-primary text-white">
                    <h4 class="mb-0"><i class="bi bi-folder"></i> 现有科目</h4>
                </div>
                <div class="card-body p-0">
                    {% if categories %}
                    <div class="list-group list-group-flush">
                        {% for category in categories %}
                        <div class="list-group-item d-flex justify-content-between align-items-center">
                            <div>
                                <span class="badge me-2" style="background-color: {{ category.color }}; padding: 8px 12px;">
                                    &nbsp;
                                </span>
                                <strong>{{ category.name }}</strong>
                                <span class="badge bg-secondary ms-2">{{ category.todo_count }} 个任务</span>
                            </div>
                            <form method="post" class="d-inline" 
                                  onsubmit="return confirm('确定要删除科目 {{ category.name }} 吗？');">
                                {% csrf_token %}
                                <input type="hidden" name="action" value="delete">
                                <input type="hidden" name="category_id" value="{{ category.id }}">
                                <button type="submit" class="btn btn-sm btn-outline-danger">
                                    <i class="bi bi-trash"></i> 删除
                                </button>
                            </form>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="p-4 text-center text-muted">
                        <i class="bi bi-inbox" style="font-size: 3rem;"></i>
                        <p class="mt-3">还没有创建科目，快来添加第一个吧！</p>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    
    <div class="row">
        <div class="col-12">
            <div class="alert alert-info">
                <h5><i class="bi bi-info-circle"></i> 科目分类说明</h5>
                <ul class="mb-0">
                    <li>可以为不同的考研科目创建分类，如：英语、数学、政治、专业课等</li>
                    <li>每个科目可以设置不同的颜色标签，便于快速识别</li>
                    <li>删除科目时，该科目下的任务不会被删除，只是不再关联科目</li>
                    <li>建议根据自己的考研科目合理规划分类</li>
                </ul>
            </div>
        </div>
    </div>
    
    <div class="text-center mt-3">
        <a href="{% url 'todo:index' %}" class="btn btn-primary">
            <i class="bi bi-arrow-left"></i> 返回待办列表
        </a>
    </div>
</div>

<script>
// 同步颜色选择器和文本框
document.getElementById('color').addEventListener('input', function() {
    document.getElementById('color-text').value = this.value;
});
</script>
{% endblock %}

